<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: LanguageDupCheck.php 361 2010-02-03 08:08:44Z steen.rabol@gmail.com $
 *
 */
Prado::using('Application.Common.Data.PortalLanguageStringRecord');
class LanguageDupCheck extends PortalAdminPage
{
	public static function ToolMenuName()
	{
		return Prado::localize('Check duplicate strings');
	}

	public function onLoad($param)
	{
		parent::onLoad($param);

		$this->setAdminPageTitle("Check language");

		if(!$this->IsPostBack)
		{
			$dr = $this->DataAccess->createCommand("select culture,name from tbllanguages where active=1")->query();
			$rows = $dr->readAll();
			$this->dlSourceLanglist->PromptText	= Prado::localize("Select");
			$this->dlSourceLanglist->PromptValue	= 0;
			$this->dlSourceLanglist->DataSource	= $rows;
			$this->dlSourceLanglist->dataBind();
		}
	}

	public function CheckLanguage()
	{
		if($this->IsValid)
		{
			$res = array();
			$source	= $this->dlSourceLanglist->SelectedValue;

			$dr	= $this->DataAccess->createCommand("select * from tbllangstrings where culture='$source'")->query();
			if($dr)
			{
				$rows = $dr->readAll();
				$cnt = 0;
				foreach($rows as $row)
				{
					$destString	= PortalLanguageStringRecord::finder()->find('culture = ? AND fromvalue = ? and id != ?', $source, trim($row['fromvalue']),$row['id']);
					if($destString !== null)
					{
						$res[] =  array('fromvalue'  => $row['fromvalue'], 'tovalue' => $row['tovalue']);
						$destString->delete();
					}
					$cnt++;
				}
			}

			$this->pnlLangCheckStart->Visible = false;
			$this->pnlLangCheckResult->Visible = true;

			$this->Repeater->DataSource	= $res;
			$this->Repeater->dataBind();

			if(count($res) > 0)
			{
				$this->lblLangCheckTxt->Text = Prado::localize('The folowing strings where deleted in the selected language');
			}
			else
			{
				$this->lblLangCheckTxt->Text = Prado::localize('No strings where deleted from the source language');
			}
		}
	}
}
?>